﻿// pika.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// Developer : C.F.Kwok(RBG) 2023-7-10

#include <stdio.h>
#include "pikascript.h"
#include "pikaVM.h"

char helpmsg[]=\
"這套源碼可根據下列選擇而編譯為五種執行方式。\n\
所對應的執行程序已分別抄送到example_exe 文件夾下\n\
的子文件夾，對應如下：\n\
選項\t文件夾\n\
START_FROM_FIRWARE\tstart_from_firmware\n\
START_FROM_STRING\tstart_from_string\n\
START_FROM_LIB\tstart_from_lib\n\
RUN_SINGLE_FILE\trun_single_file\n\
RUN_MULTI_FILES\trun_multi_files\n\
";


//-- only select one of the following:
// NOTE, this is already defined in property sheet of related config
//#define START_FROM_FIRMWARE  // related to config: firmware_start_Debug (x64)
//#define START_FROM_STRING    // related to config: string_start_Debug (x64)
//#define RUN_SINGLE_FILE      // related to config: single_file_run_Debug (x86)
//#define RUN_MULTI_FILES
//#define START_FROM_LIB
//------------------------
#define START_FROM_FIRMWARE  0
#define START_FROM_STRING    1
#define RUN_SINGLE_FILE      2
#define RUN_MULTI_FILES      3
#define START_FROM_LIB       4
//
// 
//#define NO_SHELL

int main()
{
    printf("[info] system init ok\r\n");
    printf(helpmsg);
#if PIKA_STARTUP_TYPE_INT == START_FROM_FIRMWARE
    // start from firmware
    PikaObj* pikaMain = pikaScriptInit(); // no dependancy, need precompile
#endif

#if PIKA_STARTUP_TYPE_INT == START_FROM_STRING
    // start from string
    PikaObj* pikaMain = pikaScriptInit(); // no dependancy, need precompile
    obj_run(pikaMain, "print('** start from string by calling obj_run')"); // no dependancy, compile in runtime, slower
#endif

#if PIKA_STARTUP_TYPE_INT == RUN_SINGLE_FILE
    // run single file
    PikaObj* pikaMain = pikaScriptInit(); // no dependancy, need precompile
    pikaVM_runSingleFile(pikaMain, "test2.py");
#endif

#if PIKA_STARTUP_TYPE_INT == RUN_MULTI_FILES
    // run multiple file,
    // note* need a folder: pikascript-api for storing the compiled result
    PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
    pikaVM_runFile(pikaMain, "test_mfiles.py");
#endif

#if PIKA_STARTUP_TYPE_INT == START_FROM_LIB
    // direct start from library
    // no compile at runtime, save flash life, start faster
    PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
    obj_linkLibraryFile((PikaObj*) pikaMain, "pikascript-api/pikaModules.py.a");
    obj_runModule(pikaMain, "start_from_lib");
#endif

#ifndef NO_SHELL
    // start with interactive
    pikaScriptShell(pikaMain);  // need pika_platform_getchar() support
#endif
   
}

// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单

// 入门使用技巧: 
//   1. 使用解决方案资源管理器窗口添加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件，或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来，若要再次打开此项目，请转到“文件”>“打开”>“项目”并选择 .sln 文件
